<template>
  <v-dialog :title="title" :close-on-click-modal="false" v-model="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''" :disabled="method==='view'" label-width="150px">
      <el-row>

        <el-col :span="24">
          <el-form-item label="质保金支付金额(元)" prop="currentPayAmount" :rules="[{required: true, message:'质保金支付金额不能为空', trigger:'blur'},{message:'智能填写数字', validator: validator.isNumber}
                 ]">
            <el-input v-model="inputForm.currentPayAmount" placeholder="请填写质保金支付金额"></el-input>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="24">
          <el-form-item label="质保金应付金额(元)" prop="mustPayAmount" :rules="[{required: true, message:'质保金应付金额不能为空', trigger:'blur'},{message:'智能填写数字', validator: validator.isNumber}
                 ]">
            <el-input v-model="inputForm.mustPayAmount" placeholder="请填写质保金应付金额"></el-input>
          </el-form-item>
        </el-col> -->
        <el-col :span="24">
          <el-form-item label="质保金支付时间" prop="payTime" :rules="[
                 ]">
            <el-date-picker style="width: 100%;" v-model="inputForm.payTime" type="datetime" value-format="YYYY-MM-DD HH:mm:ss" placeholder="选择日期时间">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注" prop="remark" :rules="[
                 ]">
            <el-input v-model="inputForm.remark" placeholder="请填写备注" type="textarea" :rows="6"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="visible = false" icon="circle-close">关闭</el-button>
        <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" icon="circle-check" v-noMoreClick>确定</el-button>
      </span>
    </template>
  </v-dialog>
</template>

<script>
import GridSelect from '@/components/gridSelect'
import purchaseDepositService from '@/api/deposit/purchaseDepositService'
import purchaseService from '@/api/purchase/purchaseService'
import tPurchaseContractService from '@/api/contract/tPurchaseContractService'
import projectMainService from '@/api/project/projectMainService'
export default {
  data() {
    return {
      title: '',
      method: '',
      visible: false,
      loading: false,
      purchaseService: purchaseService,
      tPurchaseContractService: tPurchaseContractService,
      projectMainService: projectMainService,
      inputForm: {
        id: '',
        purchase: {
          id: ''
        },
        contract: {
          id: ''
        },
        project: {
          id: ''
        },
        currentPayAmount: '',
        mustPayAmount: '',
        payTime: '',
        remark: ''
      }
    }
  },
  components: {
    GridSelect
  },
  created() {
  },
  methods: {
    init(method, id) {
      this.method = method

      if (method === 'add') {
        this.inputForm.id = '';
        this.inputForm.purchase.id = id.purchase.id;
        this.inputForm.contract.id = id.contract.id;
        this.inputForm.project.id = id.project.id;
        this.title = `新建采购质保金`
      } else if (method === 'edit') {
        this.inputForm.id = id
        this.title = '修改采购质保金'
      } else if (method === 'view') {
        this.inputForm.id = id
        this.title = '查看采购质保金'
      }
      this.visible = true
      this.loading = false
      this.$nextTick(() => {
        this.$refs.inputForm.resetFields()
        if (method === 'edit' || method === 'view') { // 修改或者查看
          this.loading = true
          purchaseDepositService.queryById(this.inputForm.id).then((data) => {
            this.inputForm = this.recover(this.inputForm, data)
            this.loading = false
          })
        }
      })
    },
    // 表单提交
    doSubmit() {
      this.$refs['inputForm'].validate((valid) => {
        if (valid) {
          this.loading = true
          purchaseDepositService.save(this.inputForm).then((data) => {
            this.visible = false
            this.$message.success(data)
            this.$emit('refreshDataList')
            this.loading = false
          }).catch(() => {
            this.loading = false
          })
        }
      })
    }
  }
}
</script>

  
